package cn.jly.spring.annotation.ioc.config;

import cn.jly.spring.annotation.ioc.bean.Cat;
import cn.jly.spring.annotation.ioc.bean.Dog;
import cn.jly.spring.annotation.ioc.bean.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * bean生命周期方法
 * <p>
 * 1. 指定初始化和销毁方法
 * initMethod, destroyMethod
 * <p>
 * 2. InitializingBean, DisposableBean
 * 3. JSR250规范 @PostConstruct, bean创建完成，并且属性赋值完成，然后执行初始化
 *    @PreDestroy 在容器进行销毁之前，提醒进行处理工作
 * 4. beanPostProcessor bean的后置处理器
 *      postProcessBeforeInitialization
 *      postProcessAfterInitialization
 *
 *
 * @author lanyangji
 * @description 研究生命周期的配置类
 * @date 2020/11/12 下午 4:33
 */
//@Configuration
@ComponentScan(basePackages = {"cn.jly.spring.annotation.ioc"})
public class MainConfigOfLifeCycle {

    @Bean(initMethod = "init", destroyMethod = "destroy")
    public Person person() {
        return new Person("张三", 23);
    }

    @Bean
    public Cat cat() {
        return new Cat();
    }

    @Bean
    public Dog dog() {
        return new Dog();
    }
}

